﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WarOfDev.EF;
namespace WarOfDev.Core.Configuration
{
    public class ExperienceValueEntity
    {
        public int Level { get; set; }
        public string LevelName { get; set; }
        public int InitialExperienceValue { get; set; }
        public int LimitedExperienceValue { get; set; }
    }

    public class ExperienceValueSetting
    {
        public const int minimumLevel = 1;
        public const int maxLevel = 14;

        private static List<ExperienceValueEntity> list;

        public static int GetLevelByExperienceValue(Developer onwer)
        {
            var experienceValue = onwer.ExperienceValue;
            if (experienceValue < 500){
                onwer.GameLevel = 1;
            }
            else if (experienceValue < 1200){
                onwer.GameLevel = 2;
            }
            else if (experienceValue < 2500)
            {
                onwer.GameLevel = 3;
            }
            else if (experienceValue < 5000)
            {
                onwer.GameLevel = 4;
            }
            else if (experienceValue < 8000)
            {
                onwer.GameLevel = 5;
            }
            else if (experienceValue < 12000)
            {
                onwer.GameLevel = 6;
            }
            else if (experienceValue < 20000)
            {
                onwer.GameLevel = 7;
            }
            else if (experienceValue < 30000)
            {
                onwer.GameLevel = 8;
            }
            else if (experienceValue < 50000)
            {
                onwer.GameLevel = 9;
            }
            else if (experienceValue < 80000)
            {
                onwer.GameLevel = 10;
            }
            else if (experienceValue < 120000)
            {
                onwer.GameLevel = 11;
            }
            else if (experienceValue < 200000)
            {
                onwer.GameLevel = 12;
            }
            else if (experienceValue < 300000)
            {
                onwer.GameLevel = 13;
            }
            else 
            {
                onwer.GameLevel = 14;
            }



            return onwer.GameLevel;
        }


        static ExperienceValueSetting()
        {
            list = new List<ExperienceValueEntity> { 
                new ExperienceValueEntity{Level=1,LimitedExperienceValue=500,LevelName="初学弟子"},
                new ExperienceValueEntity{Level=2,LimitedExperienceValue=1200,LevelName="初学弟子"},
                new ExperienceValueEntity{Level=3,LimitedExperienceValue=2500,LevelName="初入江湖"},
                new ExperienceValueEntity{Level=4,LimitedExperienceValue=5000,LevelName="初入江湖"},
                new ExperienceValueEntity{Level=5,LimitedExperienceValue=8000,LevelName="初入江湖"},
                new ExperienceValueEntity{Level=6,LimitedExperienceValue=12000,LevelName="江湖新秀"},
                new ExperienceValueEntity{Level=7,LimitedExperienceValue=20000,LevelName="江湖少侠"},
                new ExperienceValueEntity{Level=8,LimitedExperienceValue=30000,LevelName="江湖大侠"},
                new ExperienceValueEntity{Level=9,LimitedExperienceValue=50000,LevelName="侠之大者"},
                new ExperienceValueEntity{Level=10,LimitedExperienceValue=80000,LevelName="一派掌门"},
                new ExperienceValueEntity{Level=11,LimitedExperienceValue=120000,LevelName="一代宗师"},
                new ExperienceValueEntity{Level=12,LimitedExperienceValue=200000,LevelName="武林盟主"},
                new ExperienceValueEntity{Level=13,LimitedExperienceValue=300000,LevelName="东方不败"},
                new ExperienceValueEntity{Level=14,LimitedExperienceValue=int.MaxValue,LevelName="独孤求败"},
            };
        }

        public static ExperienceValueEntity GetEntityByLevel(int level)
        {
            if (level < 1 || level > 14)
                throw new Exception(" un excepted level value ");

            return list.Single(e => e.Level == level);
        }
    }
}
